<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/common/taglibs.jsp"%>
<html>
<head>
<title><fmt:message key='label.appAdItem_edit.title1'/></title>
<%@include file="/common/scripts.jsp"%>
<script type="text/JavaScript">
$(function(){
    jQuery("#list1").jqGrid(
       {
          datatype : "local",
          colNames : [ "","<fmt:message key='bo.AppItem.appName'/>", "<fmt:message key='bo.AppItem.owner'/>", "<fmt:message key='bo.AppItem.appSource'/>", 
                       "<fmt:message key='bo.AppItem.appCategory'/>", "<fmt:message key='bo.AppItem.appIntro'/>"], 
          colModel : [{name:'id',index:'id', width:30, sortable: false, align :'center', fixed:true, formatter:function(cellvalue, options, rowObject){
	   			          return "<input type='radio' name='picker' value='"+cellvalue+"' />";
 			          }},
                      {name : 'appName', index : 'appName', align : "left", width : 90, sortable:true}, 
                      {name : 'owner', index : 'owner', align : "left", width : 90, sortable:true}, 
                      {name : 'appSource', index : 'appSource.id', align : "left", width : 90, sortable:true}, 
                      {name : 'appCategory', index : 'appCategory.id', align : "left", width : 90, sortable:true}, 
                      {name : 'appIntro', index : 'appIntro', align : "left", width : 120, sortable:true}], 
          pager : "#pager1",
          sortname : "appName",
          sortorder : "asc",	
          height : 373,
          onSelectRow : function(ids) {
          	var model = jQuery("#list1").jqGrid('getRowData', ids);
          	$(".appName").text(model.appName);
          	$("#appItem").val(ids);
          	$(".owner").text(model.owner);
          },
          beforeSelectRow: function(rowid, e) {
              return false;
          }
       });        
});
$(function() {
    $("#queryBtn").click(function() {
		$("#list1").jqGrid('setGridParam', 
		        {datatype:'json',url:"<c:url value='query'/>", postData:$("#queryForm").serializeObject()});
		$("#list1").trigger("reloadGrid");
    });
});
$(function(){
	$("#pick").click(function(){
		var $pick = $("input:radio[name=picker]:checked");
		if ($pick.length == 0) {
			alert("<fmt:message key='dialog.message.please.select'/>");
			return false;
		}
		
		var id = $pick.val();
		var data = $("#list1").jqGrid('getRowData',id);
		window.opener.${param.callback}(data);
		window.close();
	});
});
</script>
</head>
<body>
    <div class="popWtopHeader">
        <p class="itemTitle"><fmt:message key='label.appAdItem_edit.title1'/></p>
        <a href="javascript:void(0);" class="css_btn" style="margin-top: 5px;"  id="pick"><img class="button save" src="<c:url value='/images/icon_transparent.png'/>" /><fmt:message key='button.confirm'/></a>
    </div>

         <div class="searchContainer" style="width: 100%;">
          <form:form action="query" name="queryForm" id="queryForm" method="post" commandName="query">
            <table class="queryForm" style="width: auto;">
              <tr>
                <td><fmt:message key='bo.AppItem.appName' /></td>
                <td><form:input path="appName" size="15" cssStyle="width:100%;" /></td>
                <td><fmt:message key='bo.AppItem.owner' /></td>
                <td><form:input path="owner" size="15" cssStyle="width:100%;" /></td>
                <td><fmt:message key='bo.AppItem.appSource' /></td>
                <td><form:select path="sourceId">
                    <form:option label="" value="" />
                    <form:options items="${sourceList }" itemLabel="dictionaryName" itemValue="id" />
                  </form:select></td>
                <td><fmt:message key='bo.AppItem.appCategory' /></td>
                <td><form:select path="categoryId">
                    <form:option label="" value="" />
                    <form:options items="${categoryList }" itemLabel="dictionaryName" itemValue="id" />
                  </form:select></td>
                <td><a href="javascript:void(0)" id="queryBtn" class="css_btn"><img class="button search"
                    src="<c:url value='/images/icon_transparent.png'/>" /> <fmt:message key='button.query' /></a>
                </td>
              </tr>
            </table>
          </form:form>
        </div>
    <div class="jqgrid-container">
        <table id="list1"></table>
        <div id="pager1"></div>
    </div>
</body>
</html>